package com.example.zhangxin.myhuatuob2b.bean;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;

/**
 * Created by ZhangXin on 2016/10/11.
 */

public class AdvertList {

    public static final String IMAGE = "image";
    public static final String TYPE = "type";
    public static final String DATA = "data";
    private String image;
    private String type;
    private String data;

    public AdvertList() {
    }

    public AdvertList(String image, String type, String data) {
        this.image = image;
        this.type = type;
        this.data = data;
    }

    public static String getIMAGE() {
        return IMAGE;
    }

    public static String getTYPE() {
        return TYPE;
    }

    public static String getDATA() {
        return DATA;
    }

    public static ArrayList<AdvertList> newInstanceList(String json){
        ArrayList<AdvertList> advertLists = new ArrayList<>();
        try {
            JSONArray array = new JSONArray(json);
            int size = null == array ? 0 : array.length();
            for (int i = 0; i < size; i++) {
                JSONObject obj = array.getJSONObject(i);
                String image = obj.optString(IMAGE);
                String data = obj.optString(DATA);
                String type = obj.optString(TYPE);
                advertLists.add(new AdvertList(image, type, data));
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }
        return advertLists;
    }

    public String getImage() {
        return image;
    }

    public void setImage(String image) {
        this.image = image;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public String getData() {
        return data;
    }

    public void setData(String data) {
        this.data = data;
    }
}
